package SquareFighters;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

/**
 *
 * @author Someperson1
 */
public class Boss {

    public int h;
    public Rectangle bounds;
    Field field;
    int[] pos = new int[2];

    Boss(Field field) {
        h = field.level * 20;
        this.field = field;
        bounds = new Rectangle(0, 0, 50, 50);
        Rectangle limit = new Rectangle(field.pos[0] - 200, field.pos[1] - 200, 400, 400);
        do {
            pos[0] = (int) (Math.random() * 800) + 1;
            pos[1] = (int) (Math.random() * 750) + 1;
            checkPos();
            bounds.setLocation(pos[0] - 25, pos[1] - 25);
        } while (bounds.intersects(limit));
    }

    public void detectCollision() {
        if (bounds.intersects(field.actor.bounds)) {
            h--;
            field.score -= 10;
            field.actor.modHealth(((-2 * field.level) / 10) - 1);
            field.hframe = -10;
        }
        if (field.actor.magic != null) {
            if (bounds.intersects(field.actor.magic.bounds)) {
                if (field.actor.magic.uber) {
                    h -= 20;
                    field.score += 20;
                } else {
                    h -= 10;
                    field.score += 10;
                    field.actor.magic = null;
                    field.actor.usem = false;
                }
            }
        }
        if (field.actor.sword != null) {
            if (bounds.intersects(field.actor.sword.bounds)) {
                h -= 20;
                field.score += 20;
                field.actor.sword.uses += 3;
                if (field.actor.sword.uses >= 5) {
                    field.actor.sword = null;
                    field.actor.uses = false;
                }
            }
        }
    }

    private void checkPos() {
        if (pos[0] < 0) {
            pos[0] = field.getWidth() - 1;
        }
        if (pos[0] > field.getWidth() - 1) {
            pos[0] = 0;
        }
        if (pos[1] < 15) {
            pos[1] = field.getHeight() - 1;
        }
        if (pos[1] > field.getHeight() - 1) {
            pos[1] = 15;
        }
    }

    public void draw(Graphics g) {
        for (int i = 0; i < pos.length; i++) {
            if (pos[i] > field.pos[i]) {
                pos[i] -= 3;
            } else if (pos[i] < field.pos[i]) {
                pos[i] += 3;
            }
        }
        checkPos();
        bounds.setLocation(pos[0] - 25, pos[1] - 25);
        detectCollision();
        g.setColor(Color.MAGENTA);
        g.fillRect(pos[0] - 25, pos[1] - 25, 50, 50);
        g.setColor(Color.RED);
        g.fillRect(pos[0] - 50, pos[1] - 50, 100 * h / (field.level * 20), 5);
    }
}
